package com.itheima.service;

import com.itheima.domain.User;
import com.itheima.mapper1.UserMapper;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @author wuyiqiang
 * @2022/6/17 16:57
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 用户登录
     *
     * @param user
     * @return
     */
    public User login(User user) {
        //获取当前时间
        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.applyPattern("yyyyMMdd HHmmss a");
        Date date = new Date();

        User user1 = null;
        //查询手机判断手机号是否存在
        int byPhone = 0;
        try {
            user1 = userMapper.findByPhone(user.getPhone());
        } catch (Exception e) {
            System.out.println("查询手机存在空值================debug");
        }
        //不存在帮用户新增
        if (user1 == null) {
            user1 = new User();
            user1.setId(user.getPhone());
            user1.setPhone(user.getPhone());
            user1.setStatus(1);
            userMapper.add(user1);
        }

        return user1;
    }


}
